package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.dao.OrderDao;
import com.bw.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class springbootController {
    @Autowired
    OrderService orderService;
    @RequestMapping("/sumTotal")
    public Object sumTotal(String nowDate) {
        List<Map> maps = orderService.sumTotal(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",maps.get(0).get("total"));
        return jsonObject;
    }

    @RequestMapping("/proTotal")
    public Object proTotal(String nowDate) {
        List<Map> maps = orderService.proTotal(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray dataArray = new JSONArray();
        for (Map map : maps) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",map.get("name"));
            jsonObject1.put("value",map.get("sum"));
            dataArray.add(jsonObject1);
        }
        dataObject.put("mapData",dataArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }

    @RequestMapping("/zbTotal")
    public Object zbTotal(String nowDate) {
        List<Map> maps = orderService.zbTotal(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONArray objects = new JSONArray();
        for (Map map : maps) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",map.get("name"));
            jsonObject1.put("value",map.get("zb"));
            objects.add(jsonObject1);
        }
        jsonObject.put("data",objects);
        return  jsonObject;
    }
}
